﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Diagnostics;

namespace LowLevelGraphics.Extractors
{
    /// <summary>
    /// The COG of an object is the location where one could balance the object using just one finger. 
    /// In image terms it is where one would balance all the white pixels at a single spot.
    /// The COG is quick and easy to calculate and will change based on the object's shape or position in an image.
    /// To calculate the COG of an image add all the x,y locations of non-black pixels and divide by the number of pixels counted.
    /// The resulting two numbers (one for x and the other for y) is the COG location.
    /// </summary>
    [DebuggerDisplay("Width: {m_nWidth}, Height: {m_nHeight}, Area: {m_RectangleSpanned}, PixelCount: {m_nPixelCount}")]
    public class Blob
    {
        internal List<Point> m_aPoint = new List<Point>();

        protected int m_nWidth = -1;
        protected int m_nHeight = -1;
        protected int m_nPixelCount = -1;
        protected Point m_ptGravityCenter = new Point(-1, -1);
        protected Rectangle m_RectangleSpanned = Rectangle.Empty;
        protected int m_nID = -1;
        protected int m_nCircumference = -1;

        /// <summary>
        /// Initializes a new instance of the <see cref="Blob"/> class.
        /// </summary>
        public Blob(int _nID)
        {
            m_nID = _nID;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Blob"/> class.
        /// </summary>
        /// <param name="_blob">The _blob.</param>
        internal Blob(Blob _blob)
        {
            m_nID = _blob.m_nID;
            m_RectangleSpanned = _blob.m_RectangleSpanned;
            m_ptGravityCenter = _blob.m_ptGravityCenter;
            m_nPixelCount = _blob.m_nPixelCount;
        }

        /// <summary>
        /// Gets the height.
        /// </summary>
        /// <value>The height.</value>
        public int Height
        {
            get { return SpannedRectangle.Height; }
        }

        /// <summary>
        /// Gets the spanned rectangle.
        /// </summary>
        /// <value>The spanned rectangle.</value>
        public Rectangle SpannedRectangle
        {
            get { return m_RectangleSpanned; }
            set { m_RectangleSpanned = value; }
        }


        /// <summary>
        /// Gets the width.
        /// </summary>
        /// <value>The width.</value>
        public int Width
        {
            get { return SpannedRectangle.Width; }
        }

        /// <summary>
        /// Gets the pixel count.
        /// If all pixels in this blob are counted, this is what it returns
        /// </summary>
        /// <value>The pixel count.</value>
        public int PixelCount
        {
            get { return m_nPixelCount; }
        }

        /// <summary>
        /// Gets the circumference.
        /// </summary>
        /// <value>The circumference.</value>
        public int Circumference
        {
            get { return m_nCircumference; }
        }

        /// <summary>
        /// Gets the size.
        /// </summary>
        /// <value>The size.</value>
        public Size Size
        {
            get { return new Size(m_nWidth, m_nHeight); }
        }

        /// <summary>
        /// Gets the points.
        /// </summary>
        /// <value>The points.</value>
        public List<Point> Points
        {
            get { return m_aPoint; }
        }

        /// <summary>
        /// Gets the gravity center.
        /// </summary>
        /// <value>The gravity center.</value>
        public Point GravityCenter
        {
            get { return m_ptGravityCenter; }
        }
    }
}
